package com.xiaoxin.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoxin.lease.model.entity.ApartmentFacility;
import com.xiaoxin.lease.model.entity.FacilityInfo;
import com.xiaoxin.lease.model.enums.ItemType;
import com.xiaoxin.lease.web.admin.mapper.ApartmentFacilityMapper;
import com.xiaoxin.lease.web.admin.service.ApartmentFacilityService;
import com.xiaoxin.lease.web.admin.service.FacilityInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author liubo
* @description 针对表【apartment_facility(公寓&配套关联表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class ApartmentFacilityServiceImpl extends ServiceImpl<ApartmentFacilityMapper, ApartmentFacility>
    implements ApartmentFacilityService {


    @Autowired
    private FacilityInfoService facilityInfoService;

    @Override
    public List<FacilityInfo> selectApartmentFacilityById(Long id) {
        //根据apartmentId查询facilityId
        List<ApartmentFacility> apartmentFacilities = super.list(new LambdaQueryWrapper<ApartmentFacility>().eq(ApartmentFacility::getApartmentId, id));
        List<FacilityInfo> facilityInfoList = facilityInfoService.list(new LambdaQueryWrapper<FacilityInfo>().eq(FacilityInfo::getType, ItemType.APARTMENT).in(FacilityInfo::getId, apartmentFacilities.stream().map(f -> f.getFacilityId()).toList()));
        return facilityInfoList;
    }
}





